/** 一般常用的宏的类,继承MyMacro类
  定义了一些较为常用的宏

  By setycyas @2025-02-21
*/

#Include "MyMacro.2.ahk"

class CommonMacro extends MyMacro {

  /* 公有变量
  */
  autoFireDelay := 25 ;连发延时,注意不包括按键持续时长,所以实际连发间隔是这两者之和

  /* 构造函数
  */
  __New(faceDetector, keys){
	super.__New(faceDetector, keys)
  }

  /* 重载方法
  */
  _setMacro(){
    this.macroMap["连发A"] := this._连发A.bind(this)
	  this.macroMap["下上A"] := this._下上A.bind(this)
	  this.macroMap["下前A"] := this._下前A.bind(this)
	  this.macroMap["A后防御"] := this._A后防御.bind(this)
	  this.macroMap["下前B"] := this._下前B.bind(this)
	  this.macroMap["前冲A"] := this._前冲A.bind(this)
	  this.macroArr := ["连发A", "下上A", "下前A", "A后防御", "下前B", "前冲A"]
  }

  /* 宏函数
  */
  ;不直接绑定的连发,用于指定不同按键连发
  _连发宏(i, key){
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    this._press(i)
	  sleep(this.autoFireDelay)
    loop {
      this._press(i)
	    sleep(this.autoFireDelay)
    } until (not MyFuns.getVkState(vk))
  }
  _连发A(key){ 
	  this._连发宏(1, key)
  }
  _连发B(key){ 
	  this._连发宏(2, key)
  }
  _连发C(key){ 
	  this._连发宏(3, key)
  }
  _连发D(key){ 
	  this._连发宏(4, key)
  }
  _下上A(key){
    send("{down down}")
	sleep(30)
	send("{down up}")
	sleep(30)
	send("{up down}")
	sleep(30)
	this._down(1)
	sleep(30)
	send("{up up}")
	this._up(1)
  }
  _下前A(key){
    local face := this._face.face()
    send("{down down}")
	sleep(30)
	send("{" . face . " down}")
	sleep(30)
	send("{down up}")
	this._down(1)
	sleep(30)
	send("{" . face . " up}")
	this._up(1)
  }
  _A后防御(key){
    local back := this._face.back()
    this._down(1)
    sleep(50)
    send("{" . back . " down}")
	sleep(200)
	send("{" . back . " up}")
    while (GetKeyState(key, "P")) {
      sleep(20)
    }
    this._up(1)
  }
  _下前B(key){
    local face := this._face.face()
    send("{down down}")
	sleep(30)
	send("{" . face . " down}")
	sleep(30)
	send("{down up}")
	this._down(2)
	sleep(30)
	send("{" . face . " up}")
	this._up(2)
  }
  _前冲A(key){
	local face := this._face.face()
	send("{" . face . " down}")
	sleep(30)
	send("{" . face . " up}")
	sleep(30)
	send("{" . face . " down}")
	sleep(30)
	this._down(1)
	sleep(30)
	send("{" . face . " up}")
	sleep(30)
	this._up(1)
  }
  _蓄力A(key){
    this._down(1)
  }
  _后跳(key){
    local back := this._face.back()
    local backDown := "{" . back . " down}"
    this._down(2)
    send(backDown)
    sleep(50)
    this._up(2)
    send("{" . back . " up}")
  }
}